<?php 

/**
 * 用户信息管理
 * @copyright   Copyright (c) 2006 - 2010 DZH 友拓软件友拓通
 * @category   	用户信息
 * @package  	Action
 * @author    	黄明兴
 * @version 	2.1,2012-07-22
 */

class UserPublicAction extends BasicCommonAction {
	
	/// 默认post值处理
	protected $_default_post	=  array('query'=>array('to_hide'=>1));  
	
	/// 默认查询条件
	protected $_default_where	= 'super_admin!=1';
	
	/// 需要更新的缓存信息
	protected $_cacheDd 		= array('19','36','37'); 
	
	/// 新增前置操作	
	public function _before_insert() {
		$_POST['user_password'] && $_POST['user_password'] 		= md5($_POST['user_password']);	// 密码加密	
		$_POST['user_password_confirm'] && $_POST['user_password_confirm'] = md5($_POST['user_password_confirm']);	// 密码加密	
		$_POST['create_time']   = date("Y-m-d H:i:s");			// 账号创建时间
	}
	
	/// 重置密码	
	public function resetPasswd() {
		if (isset($_POST['user_password'])) {
			if(empty($_POST['user_password'])){
				$this->error(array('name'=>'user_password','value'=>L('require')),2);
				exit;
			}
			if ($_POST['user_password_confirm']!=$_POST['user_password']) {
				$this->error(array('name'=>'user_password','value'=>L('password_input_val_neq')),2);
				exit;
			}
			D('User')->resetPasswd(intval($_POST['id']),$_POST['user_password']);
			$this->id = intval($_POST['id']);
			$this->success(L('success_reset_password'));
			exit;
		}
		$this->rs = M('User')->find($_GET['id']);
		$this->display();			
	}
	
	/// 超管帐号管理
	public function service(){
		$rs = M('User')->getByIsSuperAdmin("1");
		$this->assign('rs',$rs);
		$this->display();
	}
    
	/// 更新超管帐号信息
	public function updateService(){
		$rs = M('User')->getByIsSuperAdmin("1");
		M('User')->setField(array('id'=>$rs['id'],'to_hide'=>intval($_POST['to_hide'])));
		$this->success(L('_OPERATION_SUCCESS_')); 
	}
	
	/// 设置显示样式
    public function setFormat() {    	
    	$this->rs = M('User')->field('id,digital_format,user_name')->find(getUser('id'));	
    	$this->display();
    }
    
     /// 保存显示样式
     public function updateFormat() {
     	M('User')->where('id='.getUser('id'))->setField('digital_format',$_POST['digital_format']);
     	getUser('digital_format',$_POST['digital_format']);
   		$this->success(L('_OPERATION_SUCCESS_'));
     }
    
}
?>